"""
健康检查 | 接口
"""

from fastapi import APIRouter

import utils.enum_utils as enum
from components.audit_log import audit
from components.response import OKResponse
from models import OK
from utils.exception_utils import BusinessError

health_router: APIRouter = APIRouter()
""" 健康检查 路由 """


@health_router.get(
    path="/server/",
    summary="健康检查 | 服务",
    response_model=OK,
)
@audit(
    model=enum.Model.SERVER,
    operation=enum.ModelOperation.CHECK,
)
async def health_server() -> OKResponse:
    return OKResponse()


@health_router.get(
    path="/db/mongodb/",
    summary="健康检查 | 数据库 | MongoDB",
    response_model=OK,
)
@audit(
    model=enum.Model.MONGODB,
    operation=enum.ModelOperation.CHECK,
)
async def health_db_mongodb() -> OKResponse:
    from biz.file_biz import FileValidator

    try:
        FileValidator.is_default_file(None)

    except Exception as _:  # noqa: ignore[broad exception]
        raise BusinessError("MongoDB 服务不可用")

    return OKResponse()
